#include "face_detect.h"
#include <opencv2/videoio.hpp>
#include <iostream>
// ref:http://man.hubwiz.com/docset/OpenCV.docset/Contents/Resources/Documents/db/d28/tutorial_cascade_classifier.html
int main( int argc, const char** argv )
{
    if (0 != init("haarcascade_frontalface_alt.xml"))
    {
        std::cout << "--(!)Error loading face cascade\n";
        return -1;
    }

#ifdef USE_GPU
    char env[] = "OPENCV_FFMPEG_CAPTURE_OPTIONS=video_codec;h264_cuvid";

    int rc = putenv(env);
    if (rc != 0){
        std::cout << "Could not set environment variables\n" << std::endl;
    }
#endif

    cv::VideoCapture capture;
    // Read the video stream
    capture.open( "face_1280_720.h264", cv::CAP_FFMPEG);
    if ( ! capture.isOpened() )
    {
        std::cout << "--(!)Error opening video capture\n";
        return -1;
    }

    cv::Mat frame;
    uint32_t index = 0;
    DetectBBox_t bboxs;
    while ( capture.read(frame) )
    {
        if( frame.empty() )
        {
            std::cout << "--(!) No captured frame -- Break!\n";
            break;
        }

        int count  = detect(frame, bboxs, index);
        std::cout << "index: " << index << " detect " << count << " faces" << std::endl;
        index++;
    }
    return 0;
}
